﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CodeGame.Networking.Serverside;

using Lidgren.Network;

namespace CodeGame.ServerObjects
{
    internal class MessagingManager
    {
        private Dictionary<string, string> Messages = new Dictionary<string, string>();

        public void PostMessage(string subject, string content)
        {
            this.Messages.Add(subject, content);
        }

        public void ReadMessage(string subject, NetConnection sender)
        {
            if (this.Messages.ContainsKey(subject))
            {
                ServerProtocolChat.SendPrivateChat(subject, this.Messages[subject], sender);
            }
            else
            {
                ServerProtocolChat.SendPrivateChat("", "Message Does not Exist", sender);
            }
        }

        public void GetAllMessages(NetConnection sender)
        {
            string str = "";

            foreach (string item in this.Messages.Keys)
            {
                str += item + '\n';
            }

            ServerProtocolChat.SendPrivateChat("", str, sender);
        }

    }
}
